﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MockPrjTeam1.Pages.Forms
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = TextBox1.Text;
            string password = TextBox2.Text;

            if (Biz.LoginBiz.IsValidLogin(username, password))
            {

                
                if (Session["username"] == null)
                {
                    Session.Add("username", "accept");
                }
                Session["username"] = TextBox1.Text;
                Entity.UserOnline UserOnline = new Entity.UserOnline();
                UserOnline.username = username;
                if (CheckBox1.Checked)
                {
                    HttpCookie myCookie = new HttpCookie("UserInfo");
                    myCookie["Username"] = username;
                    myCookie["Password"] = password;
                    myCookie.Expires = DateTime.Now.AddDays(1d);
                    Response.Cookies.Add(myCookie);
                }
                Label1.Text = "Login Success!";
                
                Response.AddHeader("refresh", "0;url=../../home.aspx");
            }
            else
            {
                Label1.Text = "UserName or Password is wrong";
            }
        }
    }
}